<?php
function getUrl($index, $urls) {
  return implode('/', array_slice($urls, 0, $index + 1));
}

function getMenuName($breadcrumb, $key = '') {

  if (!empty($breadcrumb['name'][$breadcrumb['url'][$key]])) {
    return $breadcrumb['name'][$breadcrumb['url'][$key]];
  }
  else {
    $url = getUrl($key, $breadcrumb['url']);
    $result = db_select('menu_links', 'n')
      ->fields('n', array('link_title'))
      ->condition('link_path', $url, '=')
      ->execute()
      ->fetchField();
    if ($result) {
      return $result;
    }
    else {
      if (count($breadcrumb['url']) == $key + 1) {
        if (arg(0) == 'node') {

          $node = node_load(arg(1));
          if ($node) {
            return $node->title;
          }
        }
        elseif (arg(0) == 'taxonomy') {
          return taxonomy_term_load(arg(2))->name;
        }
      }
    }
  }
}

?>

<div class="container clearfix">
  <div class="breadcrumb">
    <div class="mod mod-breadcrumb">
      <ul>
        <li><a class="home" href="<?= url() ?>">NB</a></li>
        <?php foreach ($breadcrumb['url'] as $key => $val) { ?>
          <li>
            <?php
            $flag = '';
            if ($key + 1 == count($breadcrumb['url'])) {
              $flag = 'last';
            }
            $url = getUrl($key, $breadcrumb['url']);
            if (!drupal_valid_path($url)) {
              $url = 'javascript:void(0)';
            }
            else {
              $url = url($url);
            }
            ?>
            <a class="<?= $flag ?>" href="<?= $url ?>"><?= getMenuName($breadcrumb, $key) ?></a>
          </li>
        <?php } ?>
      </ul>
    </div>
  </div>
</div>